<template>
    <el-container>
        <!-- <el-header>
            <div class="right-panel-search">
                <div class="search-input">点检任务单号</div>
                <el-input v-model="search.keywords" placeholder="请输入点检任务单号" clearable></el-input>
                <div class="search-input">设备名称</div>
                <el-input v-model="search.device_keywords" placeholder="请输入设备名称" clearable></el-input>
                <el-date-picker v-model="time" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" :size="size" />
                <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
                <sc-file-import :apiObj="$API.common.importFile" templateUrl="http://www.scuiadmin/file.xlsx" @success="success" ref="importBox"></sc-file-import>
            </div>
        </el-header> -->
        <div style="padding:0 15px;display:flex;align-items:center">
            <scFilterBar filterName="filterName" :options="options" @filterChange="changeBar" style="margin-top:15px;margin-right:150px">
                <template #default="{filterLength, openFilter}">
                    <el-badge :value="filterLength" type="danger" :hidden="filterLength<=0">
                        <el-button icon="el-icon-filter" @click="openFilter">高级查询</el-button>
                    </el-badge>
                </template>
            </scFilterBar>
            <sc-file-import :apiObj="$API.common.importFile" templateUrl="http://www.scuiadmin/file.xlsx" @success="success" ref="importBox"></sc-file-import>
        </div>
        <el-header style="height:1px"></el-header>
        <el-main class="nopadding">
            <scTable ref="table" tableName="dianRecordColumn" :apiObj="apiObj" :column="column" row-key="id" stripe remoteSort remoteFilter border :params="query">
				<el-table-column fixed type="selection" width="50"></el-table-column>
                <el-table-column fixed type="index" label="序号" align="center" width="50"></el-table-column>
                <!-- 备注 -->
<!--                <template #remark="scope">-->
<!--                    <el-popover placement="top-start" :width="200" trigger="hover" :content="scope.row.remark">-->
<!--                    <template #reference>-->
<!--                        <el-button style="padding: 5px 0;" text class="m-2" v-if="scope.row.remark">{{scope.row.remark && scope.row.remark.substring(0, 15)}}</el-button>-->
<!--                    </template>-->
<!--                    </el-popover>-->
<!--                </template>-->
                <el-table-column label="操作" align="center" fixed="right">
                    <template #default="scope">
                        <el-button-group>
                            <el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)" v-auth="'dianRecord.show'">查看</el-button>
                            <el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)" v-if="scope.row.is_create == 1">
                                <template #reference>
                                    <el-button text type="danger" size="small" v-auth="'dianRecord.delete'">删除</el-button>
                                </template>
                            </el-popconfirm>
                        </el-button-group>
                    </template>
                </el-table-column>
			</scTable>
            <!-- <scTable ref="table" :apiObj="apiObj" stripe remoteSort remoteFilter border :params="query" >
                <el-table-column type="selection"  align="center" width="50"></el-table-column>
                <el-table-column type="index" label="序号" fixed align="center" width="50"></el-table-column>
                <el-table-column label="点检任务单号" prop="task_code" align="center"></el-table-column>
                <el-table-column label="设备编号" prop="device_code" align="center"></el-table-column>
                <el-table-column label="设备名称" prop="device_title" align="center"></el-table-column>
                <el-table-column label="设备类别" prop="class_title" align="center"></el-table-column>
                <el-table-column label="点检人" prop="admin_name" align="center"></el-table-column>
                <el-table-column label="点检部门" prop="dep_name" align="center"></el-table-column>
                <el-table-column label="点检开始时间" prop="create_time" align="center"></el-table-column>
                <el-table-column label="点检结束时间" prop="create_time" align="center"></el-table-column>
                <el-table-column label="备注" prop="remark" align="center">
                    <template #default="{row}">
                        <el-popover placement="top-start" :width="200" trigger="hover" :content="row.remark">
                            <template #reference>
                                <el-button style="padding: 5px 0;" text class="m-2" v-if="row.remark">{{row.remark.substring(0, 8)}}</el-button>
                            </template>
                        </el-popover>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template #default="scope">
                        <el-button-group>
                            <el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)" v-auth="'dianRecord.show'">查看</el-button>
                            <el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)" v-if="scope.row.is_create == 1">
                                <template #reference>
                                    <el-button text type="danger" size="small" v-auth="'dianRecord.delete'">删除</el-button>
                                </template>
                            </el-popconfirm>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable> -->
        </el-main>
    </el-container>
    <recird-detail v-if="dialog.recird" ref="recirdDialog" @success="handleSuccess" @closed="dialog.recird = false" draggable></recird-detail>
    <detail-save v-if="dialog.detail" ref="detailDialog" @success="handleSuccess" @closed="dialog.detail = false" draggable></detail-save>
</template>

<script>
import recirdDetail from './addRecird';
import DetailSave from './detailSave.vue';

export default {
  components: { recirdDetail,DetailSave },
	name: "user",
	data() {
		return {
            dialog: {
				recird: false,
				detail: false,
			},
			selection: [],
            apiObj: this.$API.device.deviceDianJian.record.lists,
            query:{
                is_page:1,
            },
			search:{
                keywords:null,
                device_keywords:null,
                start_time:null,
                end_time:null,
            },
            time:"",
            column: [
                {label: "点检任务单号",prop: "task_code",width: "150",},
                {label: "设备代码",prop: "device_code",width: "150",},
                {label: "设备名称",prop: "device_title",width: "150",},
                {label: "设备类别",prop: "class_title",width: "150",},
                {label: "点检人",prop: "admin_name",width: "150",},
                {label: "点检部门",prop: "dep_name",width: "150",},
                {label: "点检开始时间",prop: "task_start_date",width: "150",sortable: true},
                {label: "点检结束时间",prop: "task_end_date",width: "150",sortable: true},
                {label: "备注",prop: "remark",width: "150",},
            ],
            options: [
                {label: '模糊查询',value: 'keywords',type: 'text',selected: true,placeholder: '请输入关键词',operator: 'include',
                    operators: [
                            {label: '包含',value: 'include',},
                            {label: '不包含',value: 'notinclude',},
                        ]},
                {label: '设备名称',value: 'title_keywords',type: 'text',selected: true,placeholder: '请输入设备名称',operator: 'include',
                    operators: [
                            {label: '包含',value: 'include',},
                            {label: '不包含',value: 'notinclude',},
                        ]},
                {label: '点检时间',value: 'create_time',type: 'daterange',operator: 'include',
                    operators: [
                            {label: '包含',value: 'include',},
                            {label: '不包含',value: 'notinclude',},
                        ]
					},
            ]
		};
	},
	watch: {},
	mounted() {
        this.getHum()
    },
	methods: {
		add(){
            this.dialog.recird = true;
			this.$nextTick(() => {
				this.$refs.recirdDialog.open("edit")
			});
        },
        // 查看
        table_show(row){
            this.dialog.detail = true
            this.$nextTick(() => {
                this.$refs.detailDialog.open('show').setData(row)
            })
        },
        //删除
		async table_del(row, index) {
			var reqData = { id: row.id }
			var res = await this.$API.device.deviceDianJian.record.delete.post(reqData);
			if (res.code == 1) {
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.$refs.table.tableData.splice(index, 1);
				this.$message.success("删除成功")
                this.$refs.table.upData(this.search)
			} else {
				this.$alert(res.message, "提示", { type: 'error' })
			}
		},
        // 搜索
        upsearch() {
            if(this.time!=null){
                this.search.start_time = this.time[0]
                this.search.end_time = this.time[1]
            }else{
                this.search.start_time = ""
                this.search.end_time = ""
            }
			this.$refs.table.upData(this.search)
		},
        // 所有人员
        async getHum(){
            var res = await this.$API.all.getAdmin.get({is_page:0});
            this.humList = res.data
            let a = {label: '点检人',value: 'admin_name',type: 'select',operator: 'include',
                    operators: [
                            {label: '包含',value: 'include',},
                            {label: '不包含',value: 'notinclude',},
                        ],selected: true,placeholder: '请选择点检人',extend: {data:[]}}
            res.data.map(item=>{
                a.extend.data.push({
                    label:item.name,
                    value:item.id
                })
            })
            this.options.push(a)
        },
        changeBar(data){
            this.search.child = data
            this.upsearch()
        },
	},
};
</script>

<style></style>
